/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;
import DBH.DBHelper;
import com.sun.org.glassfish.external.statistics.Statistic;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import javax.swing.JOptionPane;

/**
 *
 * @author Huy
 */
public class B_Nhanvien {
    DBHelper obj = new DBHelper();
    Vector v;
    private String idnv;
    private String ten ;
    private String diachi ;
    private String sodienthoai ;
    private String matkhau ;
    private String chucvu ;
    private String ngayvao ;
    public B_Nhanvien() {
    }
    public B_Nhanvien(String idnv,String ten,String diachi,String sodienthoai,String matkhau,String chucvu,String ngayvao){
        this.idnv=idnv;
        this.ten=ten;
        this.diachi=diachi;
        this.sodienthoai=sodienthoai;
        this.matkhau=matkhau;
        this.chucvu=chucvu;
        this.ngayvao=ngayvao;        
    }
        public int Insertnhanvien(B_Nhanvien b) throws SQLException
    {
        int i=0;
        try
        {
            Vector paramList=new Vector();
            paramList.add(b.getIdnv());
            paramList.add(b.getTen());         
            paramList.add(b.getDiachi());
            paramList.add(b.getSodienthoai());
            paramList.add(b.getMatkhau());
            paramList.add(b.getChucvu());
            paramList.add(b.getNgayvao());
            i=DBHelper.executeUpdate("spInsertnhanvien",paramList);
        }
        catch(SQLException sqlex)
        {
            
        }
        return i;
    }
    public int Updatenhanien(B_Nhanvien b) throws SQLException
    {
        int i=0;
        try
        {
            Vector paramList=new Vector();
            paramList.add(b.getIdnv());
            paramList.add(b.getTen());         
            paramList.add(b.getDiachi());
            paramList.add(b.getSodienthoai());
            paramList.add(b.getMatkhau());
            paramList.add(b.getChucvu());
            paramList.add(b.getNgayvao());
            i=DBHelper.executeUpdate("spUpdatenhanvien",paramList); 
        }
        catch(SQLException sqlex)
        {
            
        }
        return i;
    }
    public int Deletenhanvien(String idnv) throws SQLException
    {
        int i=0;
        try
        {
            Vector paramList=new Vector();
            paramList.add(idnv);            
            i=DBHelper.executeUpdate("spDeletenhanvien",paramList);
        }
        catch(SQLException sqlex)
        {
            
        }
        return i;
    }
    public  Vector getAllnhanvien() throws SQLException
    {
        Vector v = new Vector();
        try 
        {
            ResultSet rs = obj.executeQuery("sp_getAllnhanvien");
            while(rs.next())
            {    
                B_Nhanvien b = new B_Nhanvien();
                b.setIdnv(rs.getString(1));
                b.setTen(rs.getString(2));
                b.setDiachi(rs.getString(3));
                b.setSodienthoai(rs.getString(4));
                b.setMatkhau(rs.getString(5));
                b.setChucvu(rs.getString(6));
                Date date=rs.getDate(7);
                SimpleDateFormat dayFormat= new SimpleDateFormat("MM/dd/yyyy"); 
                String today=dayFormat.format(date.getTime()); 
                //b.setNgayvao(rs.getString(7));
                b.setNgayvao(today);
                v.add(b);  
            }
        } 
        catch(SQLException sqle) 
        {            
        }
        return v;        
    }
    public  Vector getnhanvienName(String name) throws SQLException
    {
        Vector v = new Vector();
        Vector paramList=new Vector();
        paramList.add(name);               
        try 
        {
            ResultSet rs = DBHelper.executeQuery("spGetBoth_name",paramList);
            while(rs.next())
            {                  
               B_Nhanvien b = new B_Nhanvien();
                b.setIdnv(rs.getString(1));
                b.setTen(rs.getString(2));
                b.setDiachi(rs.getString(3));
                b.setSodienthoai(rs.getString(4));
                b.setMatkhau(rs.getString(5));
                b.setChucvu(rs.getString(6));
                Date date=rs.getDate(7);
                SimpleDateFormat dayFormat= new SimpleDateFormat("MM/dd/yyyy"); 
                String today=dayFormat.format(date.getTime()); 
                //b.setNgayvao(rs.getString(7));
                b.setNgayvao(today);
                v.add(b);                        
            }
        } 
        catch(SQLException sqle) 
        {            
        }
        return v;        
    }
    public String getIdnv() {
        return idnv;
    }

    /**
     * @param idnv the idnv to set
     */
    public void setIdnv(String idnv) {
        this.idnv = idnv;
    }

    /**
     * @return the ten
     */
    public String getTen() {
        return ten;
    }

    /**
     * @param ten the ten to set
     */
    public void setTen(String ten) {
        this.ten = ten;
    }

    /**
     * @return the diachi
     */
    public String getDiachi() {
        return diachi;
    }

    /**
     * @param diachi the diachi to set
     */
    public void setDiachi(String diachi) {
        this.diachi = diachi;
    }

    /**
     * @return the sodienthoai
     */
    public String getSodienthoai() {
        return sodienthoai;
    }

    /**
     * @param sodienthoai the sodienthoai to set
     */
    public void setSodienthoai(String sodienthoai) {
        this.sodienthoai = sodienthoai;
    }

    /**
     * @return the matkhau
     */
    public String getMatkhau() {
        return matkhau;
    }

    /**
     * @param matkhau the matkhau to set
     */
    public void setMatkhau(String matkhau) {
        this.matkhau = matkhau;
    }

    /**
     * @return the chucvu
     */
    public String getChucvu() {
        return chucvu;
    }

    /**
     * @param chucvu the chucvu to set
     */
    public void setChucvu(String chucvu) {
        this.chucvu = chucvu;
    }

    /**
     * @return the ngayvao
     */
    public String getNgayvao() {
        return ngayvao;
    }

    /**
     * @param ngayvao the ngayvao to set
     */
    public void setNgayvao(String ngayvao) {
        this.ngayvao = ngayvao;
    }

    /**
     * @param ngayvao the ngayvao to set
     */
    
}
